<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="CarsTable">
    <div class="layui-card-body">
        <div class="layui-form-item">
            <label class="layui-form-label">标题：</label>
            <div class="layui-input-block">
                <input type="text" name="title" placeholder="请输入标题" value="{$vo.title|default=''}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">视频：</label>
            <div class="layui-input-block">
                <input type="hidden" name="video" placeholder="请输入标题" value="{$vo.video|default=''}" class="layui-input">
                <script>$('[name=video]').uploadOneVideo();</script>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">概述</label>
            <div class="layui-input-block">
                <textarea placeholder="" class="layui-textarea"   name="introduction">{$vo.introduction|default=""}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">附件上传</label>
            <div class="layui-input-block">
                <div class="layui-upload-list">
                    {if isset($vo.attachment) && $vo.attachment}
                        {foreach $vo.attachment as $k=>$v}
                            <div class="file-item">
                                <a href="{$v.url}" target="_blank">{$v.name}</a>
                                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger"  onclick="removeFile(this)" ><i class="layui-icon">&#xe693;</i></a>
                                <input type="hidden" name="attachment[{$k}][name]" value="{$v.name}">
                                <input type="hidden" name="attachment[{$k}][url]" value="{$v.url}">
                            </div>
                        {/foreach}
                    {/if}

                </div>
                <button type="button" class="layui-btn" data-file="mut" id="attachment" >上传附件</button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详细内容</label>
            <div class="layui-input-block">
                <textarea placeholder="" class="layui-textarea"   name="content">{$vo.content|default=""}</textarea>
            </div>
        </div>


    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type="submit">{:lang('保存数据')}</button>
        <button class="layui-btn layui-btn-danger" type="button" data-confirm="{:lang('确定要取消编辑吗？')}" data-close>{:lang('取消编辑')}</button>
    </div>
</form>

<script>
    require(['angular', 'ckeditor'], function () {

        let editor;
        editor = window.createEditor('[name="content"]');
    })
    let i = "{$vo.attachment_num|default='0'}";
    $(function () {

        /*！文件上传过程及事件处理 */
        $('#attachment').on('upload.choose', function (files) {
            // 文件选择后的事件
        }).on('upload.hash', function (event, file) {
            // file 当前文件对象
        }).on('upload.progress', function (event, obj) {
            // obj.file 当前文件对象
            // obj.event 文件上传进度事件
            // obj.number 当前上传进度值
        }).on('upload.done', function (event, obj) {
            // obj.file 当前完成的文件对象，每个文件上传成功将会调用
            // obj.data 当前文件上传后服务端返回的内容，部分云上传不会返回数据
            console.log(obj)
            let data = obj.data;
            let file = obj.file;
            if(data.code == 1){
                let html = '<div class="file-item">\n' +
                    '                        <a href="'+data.data.url+'" target="_blank" style="margin-right: 5px" >'+file.name+'</a>\n' +
                    '                        <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger" onclick="removeFile(this)" ><i class="layui-icon">&#xe693;</i></a>\n' +
                    '                        <input type="hidden" name="attachment['+i+'][name]" value="'+file.name+'">\n' +
                    '                        <input type="hidden" name="attachment['+i+'][url]" value="'+data.data.url+'">\n' +
                    '                    </div>';
                $('.layui-upload-list').append(html);
                i++;
            }
        }).on('upload.complete', function (event) {
            // 全部文件上传成功
        });
    });
    function removeFile(obj) {
        $(obj).parent().remove();
    }
</script>

